﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace XDL.Framework
{
    public static class MathHelperExtensions        
    {
        public static int NearestSuperiorPowerOf2(int n)
        {
	        return (int) Math.Pow( 2, Math.Ceiling( Math.Log( n ) / Math.Log( 2 ) ) );
        }

        const float power = 3;
        public static float PowerCurve(float value)
        {
            return (float)Math.Pow(Math.Abs(value), power) * Math.Sign(value);
        }

        public static Vector2 PowerCurve(Vector2 value)
        {
            return new Vector2(PowerCurve(value.X), PowerCurve(value.Y));
        }

        /// <summary>
        /// Checks whether a number is a power of 2
        /// </summary>
        /// <param name="value">Integer to check</param>
        /// <returns>True or false</returns>
        /// <remarks>
        /// Found at www.devmaster.net/forums/showthread.php?t=1728 
        /// </remarks>
        public static bool IsPowerOfTwo(int value)
        {
            return (value & (~value + 1)) == value;  //~value+1 equals a two's complement -value
        }
    }
}
